<h3><%= t(".heading") %></h3>
<%= link_to t("libraries.general.new"), new_library_path, class: "btn btn-secondary float-end" if policy(:library).new? %>
<p class='lead'>
  <%= t(".description") %>
</p>
<div class="row">
  <% Library.find_each do |library| %>
    <div class="col-md-6">
      <div class="card <%= "border-info" if library.default? %>">
        <div class="card-header">
          <%= Icon(icon: library.icon, label: library.icon) if library.icon %>
          <%= library.name %>
          <%= content_tag(:small, class: "text-info float-end") { t("activerecord.attributes.library.default") } if library.default? %>
        </div>
        <div class="card-body">
          <div class="float-end">
            <%= GoButton(icon: "box", icon_only: true, label: Model.model_name.human.pluralize, href: models_path(library: library.to_param), variant: "outline-secondary") %>
            <%= DoButton(icon: "radar", icon_only: true, label: t("application.navbar.scan_changes.label"), href: scans_path(library: library.to_param), method: :post, variant: "outline-warning", confirm: translate(".scan_changes.confirm")) if policy(:scan).create? %>
            <%= GoButton(icon: "pencil", label: t("general.edit"), href: edit_library_path(library), variant: :secondary) %>
          </div>
          <p>
            <%= markdownify(library.notes) if library.notes %>
          </p>
          <table class="table">
            <tr>
              <td><%= t("activerecord.attributes.library.storage_service") %></td>
              <td><%= t("libraries.storage_services.%{service}" % {service: library.storage_service}) %></td>
            </tr>
            <% if library.storage_service == "filesystem" %>
              <tr>
                <td><%= t("activerecord.attributes.library.path") %></td>
                <td><code style="word-break: break-all"><%= library.path %></code></td>
              </tr>
            <% end %>
            <% if library.storage_service == "s3" %>
              <tr>
                <td><%= t("activerecord.attributes.library.s3_endpoint") %></td>
                <td><%= library.s3_endpoint %></td>
              </tr>
              <tr>
                <td><%= t("activerecord.attributes.library.s3_bucket") %></td>
                <td><%= library.s3_bucket %></td>
              </tr>
              <tr>
                <td><%= t("activerecord.attributes.library.s3_region") %></td>
                <td><%= library.s3_region %></td>
              </tr>
            <% end %>
            <% if library.free_space %>
              <tr>
                <td><%= t(".free_space.label") %></td>
                <td><%= number_to_human_size(library.free_space, precision: 2) %></td>
              </tr>
            <% end %>
            <tr>
              <td><%= t("activerecord.attributes.library.caption") %></td>
              <td><%= library.caption %></td>
            </tr>
            <tr>
              <td><%= t("activerecord.attributes.library.tag_regex") %></td>
              <td>
                <% library.tag_regex.each do |reg| %>
                  <%= link_to t(".tag_regex.check"), models_path(library: library, missingtag: reg), {class: "btn btn-secondary"} %>
                  <code><%= reg %></code><br>
                <% end %>
                <%= if !library.tag_regex.empty? then link_to t(".tag_regex.search_missing"), models_path(library: library, missingtag: ""), {class: "btn btn-secondary"} end %>
              </td>
            </tr>
          </table>
          <div class="row">
            <%= StatBlock(title: Model, value: model_count(library: library)) %>
            <%= StatBlock(title: ModelFile, value: model_file_count(library: library)) %>
            <%= StatBlock(title: t("settings.show.total_file_size"), value: number_to_human_size(total_file_size(library: library), precision: 2)) %>
          </div>
        </div>
      </div>
    </div>
  <% end %>
</div>

<hr>
<h4><%= t(".settings") %></h4>

<%= form_with url: settings_path, method: :patch, class: "tabular-form" do |form| %>
  <%= checkbox_input_row form, "libraries[show]",
        label: t(".show.label"),
        checked: SiteSettings.show_libraries,
        help: t(".show.help") %>
  <%= render "settings/submit", form: form %>
<% end %>
